/**
 * 
 */
//------Full Tool Bar ----------------- 
//[
// ['Source','-','Save','NewPage','Preview','-','Templates'],
// ['Cut','Copy','Paste','PasteText','PasteFromWord','-','Print', 'SpellChecker', 'Scayt'],
// ['Undo','Redo','-','Find','Replace','-','SelectAll','RemoveFormat'],
// ['Form', 'Checkbox', 'Radio', 'TextField', 'Textarea', 'Select', 'Button', 'ImageButton', 'HiddenField'],
// '/',
// ['Bold','Italic','Underline','Strike','-','Subscript','Superscript'],
// ['NumberedList','BulletedList','-','Outdent','Indent','Blockquote','CreateDiv'],
// ['JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock'],
// ['BidiLtr', 'BidiRtl'],
// ['Link','Unlink','Anchor'],
// ['Image','Flash','Table','HorizontalRule','Smiley','SpecialChar','PageBreak','Iframe'],
// '/',
// ['Styles','Format','Font','FontSize'],
// ['TextColor','BGColor'],
// ['Maximize', 'ShowBlocks','-','About']
//];

/*CMS.exceptionKey = {'&ocirc;':'ô','&Ocirc;':'Ô','&acirc;':'â','&Acirc;':'Â'};
CMS.t = function(key){	
	if (typeof CMS.source[key] == "undefined") return key;
        var strTMP = CMS.source[key];        
        for(key in CMS.exceptionKey){
            strTMP = strTMP.replace(key, CMS.exceptionKey[key]);
        }
	return strTMP;
}*/
//CMS Util
//---------------------------------------------------
CMS.Util = {
    renderLanguage:function(value){
        for (var i=0;i<CMS.WEB_LANG.length;i++){
            if (value == CMS.WEB_LANG[i].code) return CMS.WEB_LANG[i].name;
        }
        return null;
    },
    tofilterListType:function(data,key,label){
        var result = [];
        for (var i=0;i<data.length;i++){
            result[i] = eval("[data[i]."+key+",data[i]."+label+"]");
        }
        return result;
    }
};
CMS.globalGridConfig = {
    totalRow   : 50,
    gridHeight : 285,
    itemPerPageArray : [[10,'10'],[25,'25'],[50,'50'],[100,'100']]//Show tren Top Toolbar
};
CMS.configToolbarCkeditor = {};
CMS.getToolbar = function(type){
	if (type == CMS.Editor.BasicType){
		return {
			toolbar : CMS.configToolbarCkeditor.Basic
		};
	}else if(type == CMS.Editor.FullType){
		return {
			toolbar : CMS.configToolbarCkeditor.Full
		};
	}else{
		return {
			toolbar : CMS.configToolbarCkeditor.Customeize
		};
	}
};
CMS.configToolbarCkeditor.Full = "Full";
CMS.configToolbarCkeditor.Customeize =  [	
    ['Maximize','-','Source'],        
    ['Cut','Copy','Paste','PasteText','PasteFromWord','-','Scayt'],
    ['Undo','Redo','-','Find','Replace','-','SelectAll','RemoveFormat'],
    ['Image','Flash','Table','HorizontalRule','Smiley','SpecialChar','PageBreak'],
    '/',
    ['Styles','Format'],
    ['Bold','Italic','Strike'],
    ['NumberedList','BulletedList','-','Outdent','Indent','Blockquote'],
    ['Link','Unlink','Anchor']
];
CMS.configToolbarCkeditor.Basic =[
    ['Source','-','Bold', 'Italic', '-', 'NumberedList', 'BulletedList', '-', 'Link', 'Unlink']
];

CMS.getSampleData = function(url){
    var result = "";    
    alert(result);
}
//Config Editor And CKFinder
CKEDITOR.config.language = CMS.CURRENTLANG;
CKEDITOR.config.skin = 'v2',
CKEDITOR.config.toolbar = CMS.configToolbarCkeditor.Customeize;
//---------------------------------------------------------------------------------------------------
CMS.CKFinder = {};
CMS.CKFinder.BrowseServer= function BrowseServer( startupPath, functionData ,relObject)
{
	// You can use the "CKFinder" class to render CKFinder in a page:
	var finder = new CKFinder();

	//Startup path in a form: "Type:/path/to/directory/"
	finder.startupPath = startupPath;

	// Name of a function which is called when a file is selected in CKFinder.
	finder.selectActionFunction = function(fileUrl, data) {CMS.CKFinder.SetFileField(fileUrl,data,relObject)}

	// Additional data to be passed to the selectActionFunction in a second argument.
	// We'll use this feature to pass the Id of a field that will be updated.
	finder.selectActionData = functionData;

	// Name of a function which is called when a thumbnail is selected in CKFinder.
	finder.selectThumbnailActionFunction = CMS.CKFinder.ShowThumbnails;

	// Launch CKFinder
	finder.popup();
}

// This is a sample function which is called when a file is selected in CKFinder.
CMS.CKFinder.SetFileField = function SetFileField( fileUrl, data ,relObject)
{
    var thumbfileUrl = fileUrl.replace("/userfiles/", "/userfiles/_thumbs/");
    
    if (relObject != '')
        $("#"+relObject).html("<img src=\""+thumbfileUrl+"\" width=\"100px\" />");
    document.getElementById( data["selectActionData"] ).value = fileUrl;
}

// This is a sample function which is called when a thumbnail is selected in CKFinder.
CMS.CKFinder.ShowThumbnails = function ShowThumbnails( fileUrl, data )
{
	// this = CKFinderAPI
	var sFileName = this.getSelectedFile().name;
	document.getElementById( 'thumbnails' ).innerHTML +=
			'<div class="thumb">' +
				'<img src="' + fileUrl + '" />' +
				'<div class="caption">' +
					'<a href="' + data["fileUrl"] + '" target="_blank">' + sFileName + '</a> (' + data["fileSize"] + 'KB)' +
				'</div>' +
			'</div>';

	document.getElementById( 'preview' ).style.display = "";
	// It is not required to return any value.
	// When false is returned, CKFinder will not close automatically.
	return false;
}
CMS.CKFinder.Delete = function(id_object,txtObject){
    if (id_object != '')
        $("#"+id_object).html("");
    $("#"+txtObject).val("");
}
